package com.just.bz_back.controller;

import com.just.bz_back.model.Admin;
import com.just.bz_back.model.dto.JsonData;
import com.just.bz_back.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/v1")
@Slf4j
public class LoginController {
    @Resource
    private AdminService adminService;

    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public JsonData Login(@RequestBody Admin admin)
    {
        log.info("请求登录{}",admin.getName());
        String  token=adminService.login(admin);
        if (token != null)
        {
            return JsonData.buildSuccess(token,0);
        }
        if (!"error".equals(token))
        {
            return JsonData.buildError("用户不存在",-1);
        }
        return JsonData.buildError("账号或密码错误",-1);
    }

}
